package SortAlgorithm;

import java.util.Arrays;

public class CountSort {
    public static void main(String[] args) {
        int[] a=new int[]{34 ,84 ,60 ,54, 7 ,48 ,90 ,99 ,70 ,55};
        System.out.println(Arrays.toString(a));
        countSort(a);
        System.out.println(Arrays.toString(a));
    }
    public static void  countSort(int[] arr){
        int max=0;
        for(int i=0;i<arr.length;i++){
            if(arr[i]>max){
                max=arr[i];
            }
        }
        int[] help=new int[max+1];
        for(int i=0;i<arr.length;i++){
            help[arr[i]]++;
        }
        //遍历辅助数组
        int count=0;
        for(int i=0;i<help.length;i++){
            while(help[i]>0){
                arr[count++]=i;
                help[i]--;
            }
        }
    }
}
